

DEFINE VARIABLE part LIKE pt_part .

DEFINE VARIABLE um LIKE pt_um .

DEFINE VARIABLE ptdesc AS CHARACTER.

DEFINE VARIABLE effdate LIKE tr_effdate .

DEFINE VARIABLE qty LIKE tr_qty_chg .

DEFINE STREAM bf.

DEFINE VARIABLE str AS CHARACTER.

INPUT FROM VALUE("f:\hk_src\audit\rctunp.csv") .

OUTPUT STREAM bf TO VALUE("f:\hk_src\audit\rct_unp.txt").

REPEAT ON ERROR UNDO, RETRY :

    IMPORT DELIMITER "," effdate part qty NO-ERROR .

    FIND FIRST pt_mstr NO-LOCK WHERE pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) 
        OR pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) + "R" NO-ERROR.

    PUT STREAM bf "@@BATCHLOAD icunrc.p" SKIP.

    EXPORT STREAM bf part.

    str = STRING(qty) + " - - """ + pt_site + """ """ + pt_loc + """ - -".

    PUT STREAM bf UNFORMATTED str SKIP.

    str = "- - - - - """ + STRING(effdate) + """ - - - -" .

    PUT STREAM bf UNFORMATTED str SKIP.

    PUT STREAM bf "@@end" SKIP.

END.
